#ifndef TCPSERVER_H
#define TCPSERVER_H

#include <QTcpServer>
#include <tcpclientsocket.h>
#include <QtConcurrent/QtConcurrentRun>
#include "../common/message.h"
#include "messagetask.h"

class TcpServer : public QTcpServer
{
    Q_OBJECT
private:
    QHash<QString, TcpClientSocket*> clientSocketMap;
    // void doOneTask(QTcpSocket*, const Message&);
public:
    TcpServer(QObject *parent = nullptr, int port = 0);
    const QHash<QString, TcpClientSocket*>& getClientSocketMap();
    void broadcast(Message*);

signals:
    void serverStatusChange(Message*);
    void doBroadCast(Message*);
public slots:
    void clientDataReady(Message*, TcpClientSocket*);
    void clientDisconected(TcpClientSocket*);


    // QTcpServer interface
protected:
    void incomingConnection(qintptr handle) override;

};

#endif // TCPSERVER_H
